<?php
/*
 *  @author Nicolas Genevaux
 * (c)nige 2008
 */
	session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head><body><div><span>

<?php
	include_once("../inc/fct.utils.php");
	if(!$_SESSION['admin']=='YOUAREANADMIN') {
		if($_POST['pass']=="root") {
			$_SESSION['admin']='YOUAREANADMIN';
		}
		else {
			$_SESSION['admin']='';
			redirect("index.php");
		}
	}
	$RACINE = "../";
	include("../inc/rea.include_haut.php");
	echo '<b>Gestion des questions posant probl&egrave;me</b>';
	echo '<br /><br />';
	echo '<a href="index.php">Disconnect</a>';
	echo '<br /><br />';
	if($_GET['voir']==1) {
		$res = doSQL('SELECT * from questionnaire WHERE identifiant="'.$_GET['id'].'"');
?>
		<br /><br />
		<b>Question</b>
		<br />
		<?= $res['question'] ?>
		<br /><br />
		<b>Reponse</b>
		<br />
		<?= $res['choix'.$res['reponse']] ?>
		<br /><br />
		<a href="?mod=1&id=<?= $res['identifiant'] ?>">Modifier</a>
<?php
	}
	else if($_GET['mod']==1 || $_POST['mod']=="Valider") {
		if($_POST['mod']=="Valider") {
			$resQ = doSQL('SELECT * from questionnaire WHERE identifiant="'.$_GET['id'].'"');
			$IDMATIERE = $resQ['identifiantmatiere'];
			include("../inc/var.points.php");
			doSQL('UPDATE exercice SET question="'.$_POST['question'].'",valide="O" ' .
					' WHERE identifiant="'.$_POST['id'].'"');
			doSQL('UPDATE exercicechoix SET choix="" ' .
					' WHERE identifiantexercice="'.$_POST['id'].'" ' .
					' AND choix="'.$_POST['reponse'].'"');
			doSQL('UPDATE exercicechoix SET choix="'.$_POST['reponse'].'" ' .
					' WHERE identifiant="'.$_POST['idchoix'].'"');
			redirect("question.php?id=".$_POST['id']);
		}
		else {
			$res = doSQL('SELECT * from questionnaire WHERE identifiant="'.$_GET['id'].'"');
?>
	<form action="" method="post">
		<br /><br />
		<b>Question</b>
		<br />
		<input type="hidden" name="id" value="<?= $_GET['id'] ?>" />
		<textarea name="question"><?= $res['question'] ?></textarea>
		<br /><br />
		<b>Reponse</b>
		<br />
		<input type="hidden" name="idchoix" value="<?= $res['idchoix'.$res['reponse']] ?>" />
		<textarea name="reponse"><?= $res['choix'.$res['reponse']] ?></textarea>
		<br /><br />
		<a href="?">Annuler</a>
		<input type="submit" name="mod" value="Valider" />
		<a href="?sup=1&id=<?= $res['identifiant'] ?>">Supprimer</a>
	</form>
<?php
		}
	}
	else if($_GET['sup']) {
		$resQ = doSQL('SELECT * from questionnaire WHERE identifiant="'.$_GET['id'].'"');
		$IDMATIERE = $resQ['identifiantmatiere'];
		include("../inc/var.points.php");
		doSQL('UPDATE inscrit SET points=points-('.($QUESTIONS*5).') WHERE ' .
				' identifiant="'.$resQ['identifiantinscrit'].'"');
		doSQL('DELETE FROM exercice WHERE identifiant="'.$_GET['id'].'"');
		doSQL('DELETE FROM exercicechoix WHERE identifiantexercice="'.$_GET['id'].'"');
		redirect("question.php?id=".$_POST['id']);
	}
	else {
		$res = doSQLArray(
			'SELECT * FROM exercicevalide,exercice WHERE ' .
			' exercice.identifiant=exercicevalide.identifiantexercice ' .
			' AND exercicevalide.valide="N"' .
			' AND exercicevalide.ratio<50 '
			);
?>
		<br /><br />
<?php
		for($i=0;$res[$i];$i++) {
?>
		<a href="?voir=1&id=<?= $res[$i]['identifiant'] ?>">Voir</a> <?= $res[$i]['question'] ?>
		<br /><br />
<?php
		}
	}
?>
</span></div>
</body>
</html>

